package com.test.activiti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.task.Task;

import java.util.List;

/**
 * @ClasName ActivitiCompleteTask
 * @Descripution
 * TODO 背后操作的表：
*       act_hi_actinst
 *      act_hi_identitylink
 *      act_hi_taskinst
 *      act_ru_identitylink
 *      act_ru_task
 * @Author leikw
 * @Date 2021/9/1 15:52
 * @Version V1.0
 */
public class ActivitiCompleteTask {

//    public static void main(String[] args) {
//        //1.创建ProcessEngine对象
//        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
//        //2.得到TaskService实例
//        TaskService taskService = defaultProcessEngine.getTaskService();
//
//        //3.根据任务id处理任务，结合ActivitiTaskQuery用户任务列表的查询操作，可以得到任务id
//        //2505
//        taskService.complete("2505");
//    }

    //lishi完成自己的任务
//    public static void main(String[] args) {
////        //1.得到ProcessEngine对象
////        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
////
////        //2.得到TaskService对象
////        TaskService taskService = processEngine.getTaskService();
////
////        //3.处理任务,结合当前用户任务列表的查询操作的话,任务ID:5002
////        taskService.complete("12502");
////
////
////    }

    public static void main(String[] args) {
        //1.得到ProcessEngine对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到TaskService对象
        TaskService taskService = defaultProcessEngine.getTaskService();

        //3.根据流程定义的key，负责人assignee来实现当前用户的任务列表的查询
        Task task = taskService.createTaskQuery()
                .processDefinitionKey("myProcess").taskAssignee("wangwu").singleResult();

        System.out.println(task.getId());
        //4.处理任务,结合当前用户任务列表的查询操作的话,任务ID:5002
        taskService.complete(task.getId());
    }

}
